package com.guigu.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.pojo.SystemUsers;
import com.guigu.service.SystemUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class SystemUsersController {

    @Autowired
    SystemUsersService systemUsersService;

    //系统后端登录
    @RequestMapping("adminlogin.action")
    public SystemUsers adminlogin(SystemUsers systemUsers){

        System.out.println("-------"+systemUsers);

        return systemUsersService.adminlogin(systemUsers);
    }

    //获取所有员工
    @RequestMapping("queryallUsers.action")
    public Page<SystemUsers> queryallUsers(@RequestParam(value = "pageno",defaultValue = "1") Integer pageno,
                                     @RequestParam(value = "pagesize",defaultValue = "5") Integer pagesize,
                                     SystemUsers systemUsers){
        System.out.println(systemUsers);
        Page page = systemUsersService.queryallUsers(pageno,pagesize,systemUsers);

//        for (Object obj : page.getRecords()) {
//            System.out.println("---------"+obj);
//        }

        return systemUsersService.queryallUsers(pageno,pagesize,systemUsers);

    }

    //员工状态修改
    @RequestMapping("alterSystembyid.action")
    public Map alterSystembyid(SystemUsers systemUsers){

        System.out.println(systemUsers);

        return systemUsersService.alterSystembyid(systemUsers);
    }

    //添加员工
    @RequestMapping("addbySystem.action")
    public Map addbySystem(Integer roleName,SystemUsers systemUsers, MultipartFile img, HttpServletRequest request){

        System.out.println(systemUsers);

        System.out.println(roleName);

        System.out.println(img);

        return systemUsersService.addbySystem(roleName,systemUsers,img,request);
    }

    //根据id查询员工
    @RequestMapping("querybyid_Systemuser.action")
    public SystemUsers querybyid(SystemUsers systemUsers){

        System.out.println(systemUsers);
        return systemUsersService.querybyid(systemUsers);
    }

    //修改
    @RequestMapping("editStaff.action")
    public Map editStaff(SystemUsers systemUsers,MultipartFile img,Integer rid,HttpServletRequest request){

        System.out.println("角色id"+rid);
        System.out.println(systemUsers);
        System.out.println(img);

        return systemUsersService.editStaff(systemUsers,img,rid,request);
    }

    //判断重复
    @RequestMapping("querybyname.action")
    public Map querybyname(SystemUsers systemUsers){

        return systemUsersService.querybyname(systemUsers);
    }


    //修改密码
    @RequestMapping("editPwd.action")
    public Map editPwd(SystemUsers systemUsers){

        return systemUsersService.editPwd(systemUsers);
    }
}
